<dl class="pop-area">
  <dt>名称：<input type="text" id="title" value="{$userCategory['title']}" class="s-txt" style="width:245px"></dt>
  <dd style="text-align:center;margin:15px 0 0 ">
        <php>if (isset($userCategory)) {</php>
        <input type="button" class="btn_b" onclick="editUserCategory()" value="确定" />
        <php>}else {</php>
        <input type="button" class="btn_b" onclick="addUserCategory()" value="确定" />
        <php>}</php>
        <input type="button" class="btn_w ml10" onclick="cancel()" value="取消" />
  </dd>
  <div class="clear"></div>
</dl>

<script type="text/javascript">
// 添加身份
function addUserCategory() {
	var title = $.trim($('#title').val());
	var pid   = "{$pid}";
	if(title == '') {
		ui.error('请输入名称');
		return false;
	}
	// 提交修改
	$.post("{:U('admin/User/doAddUserCategory')}", {title:title,pid:pid}, function(res){
	    if (res == '0') {
	        ui.error('保存失败');
            return false;
        } else {
        	var url = "{:U('admin/Tool/area')}";
            var html = '';
            html += '<tr overstyle="on" id="category_'+res+'">';
            html += '<td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="'+res+'"></td>';
            html += '<td>'+res+'</td>';
            html += '<td><div style="float:left"><span style="color:black;cursor:auto;" id="category_title_' + res + '">'+title+'</span></div></td>';
            html += '<td><a href="javascript:void(0);" onclick="edit('+res+');">编辑</a> ';
            if(pid == 0) {
                html += '<a href="'+U('admin/User/category')+'&pid='+res+'">下级管理</a> ';
            }
            html += '<a href="javascript:void(0);" onclick="del('+res+');">删除</a> ';
            html += '</tr>';
            $('#category_list').append(html);
            ui.success('添加成功');
            ui.box.close();
		}
	});
};
// 编辑地区
function editUserCategory() {
	var title = $.trim($('#title').val());
	var cid = "{$userCategory['user_category_id']}";
	
	if(title == '') {
        ui.error('请输入名称');
        return false;
    }
	
	//判断名称是否有变化
	if(title == "{$userCategory['title']}") {
		ui.error('名称无变化，未提交修改');
		ui.box.close();
		return false;
	}

	//判断是否有重名
	$.post("{:U('admin/User/doEditUserCategory')}", {user_category_id:cid, title:title}, function(res){
		if (res == '0') {
            ui.error('保存失败');
        }else {
        	$('#category_title_' + cid).html(title);
            ui.success('保存成功');
            ui.box.close();
        }
	});
}
// 关闭弹窗
function cancel() {
	ui.box.close();
}
</script>
